package blackhouse.laobi.collection.day15;
import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class GenericDemo2 {
	public static void main(String[] args) {
	 TreeSet<String> ts  = new TreeSet<String>(new LenComparator());
	 ts.add("abcd");
	 ts.add("cc");
	 ts.add("cba");
	 ts.add("aaa");
	 ts.add("z");
	 ts.add("hahaha");
     
	 Iterator<String>  it = ts.iterator();
	 while(it.hasNext()){
		 String s = it.next();
		 System.out.println(s);
	 }
	}
}
class LenComparator implements Comparator<String>{
	public int compare(String s1,String s2){
		int num  = new Integer(s2.length()).compareTo(s1.length());
		if(num==0)
			return s2.compareTo(s1);
		return num;
	}
}
